package com.my.chapter14;

public class Test {
    public static void main(String[] args) {
        Class<?> c = null;
        try {
            c = Class.forName("com.my.chapter14.Man");
        } catch(ClassNotFoundException e) {
            System.out.println("Can't find Man");
            return;
        }

        System.out.println("Class name: " + c.getName() +
                " is interface? [" + c.isInterface() + "]");
        System.out.println("Simple name: " + c.getSimpleName());
        System.out.println("Canonical name : " + c.getCanonicalName());
        System.out.println("");
        for(Class<?> face : c.getInterfaces())
            System.out.println(face.getSimpleName());
        System.out.println("");

        Class<?> up = c.getSuperclass();
        Object obj = null;
        try {
            // Requires default constructor:
            obj = up.newInstance();
        } catch(InstantiationException e) {
            System.out.println("Cannot instantiate");
            return;
        } catch(IllegalAccessException e) {
            System.out.println("Cannot access");
            return;
        }
        System.out.println(obj.getClass());
    }
}

interface HasHouse{}

class Human{
    Human(){}
    Human(int i){}
}

class Man extends Human implements HasHouse{
    Man(){super(1);}
}

/*Output：
Class name: com.my.chapter14.Man is interface? [false]
Simple name: Man
Canonical name : com.my.chapter14.Man

HasHouse

class com.my.chapter14.Human
*/

